package com.auth.practice.application.controller;

import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

@Component
public class PolicyDispatcher {
    public void dispatcher(Map<String, Object> dataMap) {
        try {
            String url = dataMap.get("ok").toString();
            String[] classPath = url.split("->");
            Class<?> aClass = Class.forName(classPath[1]);
            Method method = aClass.getMethod(classPath[0], Map.class);
            Map<String, Object> paramMap = new HashMap<>();
            paramMap.put("hello", "开始执行反射分发调用....");
            Object invoke = method.invoke(aClass.newInstance(), paramMap);
            System.out.println("执行结果为：" + invoke);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
